/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Description: 与qos相关接口的适配
 * Author: lanzeze
 * Create: 2023-06-25
 */
#include "adapter_qos.h"
#include "dlqos_function.h"
#include "adapter_rts.h"

using namespace hccl;

HcclResult hrtGetQosConfig(const u32 groupId, u32 &qosCfg)
{
#if (!defined(HCCD)) && (!defined(CCL_KERNEL))
    s32 deviceLogicId = 0;
    CHK_RET(hrtGetDevice(&deviceLogicId));
    
    QosConfig info;
    info.qos = 0xFU;
    info.mpamId = 0xFFU;
    // 防止后续rtGetQosConfig下线影响业务正常运行
    if (RT_GET_QOS_CONFIG(groupId, deviceLogicId, &info) == QosErrorCode::QOS_NULL_FUNC) {
        HCCL_WARNING("rtGetQosConfig is undefined!");
        return HCCL_SUCCESS;
    }

    QosErrorCode qosRet = rtGetQosConfig(groupId, deviceLogicId, &info);
    CHK_PRT_RET((qosRet != QosErrorCode::QOS_SUCCESS),
        HCCL_ERROR("[Get][QosConfig]errNo[0x%016llx] rtGetQosConfig fail, groupId:%x, deviceid:%d, ret:%u",
            HCOM_ERROR_CODE(HCCL_E_PARA), groupId, deviceLogicId, qosRet), HCCL_E_PARA);
    
    // 将info的mpamid和qos传给qosCfg，其中 0~3位放 qos; 4~11位 mpamid; 12位以后无用，设置为全1，确保qos不使能时能取到无效值
    qosCfg = \
        ((static_cast<u32>(info.qos) & 0xFU) | ((static_cast<u32>(info.mpamId) & 0xFFU) << 4U)) | (0xFFFFFU << 12U);
    HCCL_DEBUG("Call hrtGetQosConfig, info.qos value[%u] info.mpamId value[%u] qosCfg value[%x]", \
        info.qos, info.mpamId, qosCfg);
    return HCCL_SUCCESS;
#else
    return HCCL_SUCCESS;
#endif
}
